<?php


namespace App\Http\Controllers\applets\model;


use Illuminate\Support\Facades\DB;

class PushLogModel
{
    public static function add($param){
        return DB::table('t_push_log')->insert($param);
    }

    public static function queryAll($where=[],$param=[],$page){
        $field = ['p.id','p.remark','p.status','a.username','p.operation','p.message','p.details','p.create_time'];
        if(isset($param['type']) && $param['type']!=1){
            return DB::table('t_push_log as p')
                ->leftJoin('t_admin as a','p.admin_id','=','a.id')
                ->where($where)
                ->where("$param[field]",'like','%'.$param["$param[field]"].'%')
                ->offset($page['startSize'])
                ->limit($page['pageSize'])
                ->orderByDesc('id')
                ->get($field);
        }
        return DB::table('t_push_log as p')
            ->leftJoin('t_admin as a','p.admin_id','=','a.id')
            ->where($where)
            ->offset($page['startSize'])
            ->limit($page['pageSize'])
            ->orderByDesc('id')
            ->get($field);
    }

    public static function queryCount($where=[],$param=[]){
        if(isset($param['type']) && $param['type']!=1){
            return DB::table('t_push_log as p')
                ->leftJoin('t_admin as a','p.admin_id','=','a.id')
                ->where($where)
                ->where("$param[field]",'like','%'.$param["$param[field]"].'%')
                ->count('p.id');
        }
        return DB::table('t_push_log as p')
            ->leftJoin('t_admin as a','p.admin_id','=','a.id')
            ->where($where)
            ->count('p.id');
    }
}